package com.briup.es.config.web;

import com.briup.es.interceptor.AuthInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class SpringWebConfig implements WebMvcConfigurer {

    private final AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                // 配置拦截哪些路径，即哪些路径需要被认证
                .addPathPatterns("/**")
                // 设置白名单，即无需登录认证的请求名单
                .excludePathPatterns("/user/login","/user/register",
                        "/book/showBooks","/book/searchBook",
                        "/book/findByCategory/*","/category/list",
                        "/upload","/profile/**",
                        "/common/download**",
                        "/common/download/resource**",
                        "/swagger-ui.html",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/*/api-docs/**",
                        "/druid/**",
                        "/favicon.ico",
                        "/doc.html");
    }
}
